import * as fs from 'node:fs';
import * as path from 'node:path';

const isProd = process.env.NODE_ENV === 'prod';

function parseEnv() {
  console.log('env', process.env.NODE_ENV);
  let env: any = null;
  if (isProd) {
    env = path.resolve('.env.prod');
  } else {
    env = path.resolve('.env.local.dev');
    if (!fs.existsSync(env)) {
      env = path.resolve('.env.dev');
    }
  }
  if (!env || !fs.existsSync(env)) throw new Error('缺少环境配置文件');
  return { path: env };
}
//
export default parseEnv();
